package com.koron.standard.holiday.service;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.koron.standard.bean.query.PageQuery;
import com.koron.standard.holiday.bean.po.Holiday;
import com.koron.standard.holiday.bean.query.HolidayQuery;
import com.koron.standard.holiday.mapper.HolidayMapper;
import org.springframework.stereotype.Service;

/**
 * 放假日历(Holiday)表服务实现类
 *
 * @author jzp
 * @since 2023-05-29
 */
@Service
public class HolidayService extends ServiceImpl<HolidayMapper, Holiday> {

    public Page<Holiday> page(PageQuery<Holiday> pageQuery, HolidayQuery query) {
        Page<Holiday> page = pageQuery.convertPage();
        QueryWrapper<Holiday> wrapper = new QueryWrapper<>();
        wrapper.eq(query.getHolidayDate() != null, "holiday_date", query.getHolidayDate());
        wrapper.eq(query.getHolidayWeek() != null, "holiday_week", query.getHolidayWeek());
        wrapper.like(query.getHkName() != null, "hk_name", query.getHkName());
        wrapper.like(query.getZhName() != null, "zh_name", query.getZhName());
        if (CollUtil.isNotEmpty(query.getDates())) {
            wrapper.between("c_experiment.create_time", query.getDates().get(0), query.getDates().get(1));
        }
        getBaseMapper().selectPage(page, wrapper);
        return page;
    }

}
